import { fileURLToPath, URL } from "node:url";
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
const getFullPath = (relationPath: string) => {
  return fileURLToPath(new URL(relationPath, import.meta.url));
};

export default defineConfig(({ command: string, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  return {
    base:"./",
    plugins: [
      vue(),
      vueJsx(),
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    resolve: {
      alias: {
        "@": getFullPath("./src"),
        "@a": getFullPath("./src/assets"),
        "@c": getFullPath("./src/components"),
        "@b": getFullPath("./src/blocks"),
        "@v": getFullPath("./src/views"),
        "@vp": getFullPath("./src/view-provider"),
        "@s": getFullPath("./src/stores"),
        "@r": getFullPath("./src/router"),
        "@u": getFullPath("./src/use"),
      },
    },
    define: {
      __APP_ENV__: JSON.stringify(env.VITE_API_URL),
    },
  };
});
